<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<include file="Public:meta" />
</head>
<body id="main_page" style="padding-top:3px;">
<div class="container">
    <div class="box">
        <form id="frmConfig" method="post" action="{$Action}" enctype="multipart/form-data" >
            <div class="box-header" id="c1">
                <h4>基本设置</h4>
            </div>
            <div class="box-content">
                <table class="boxtable">
                    <tr>
                        <th>是否启用七牛云</th>
                        <td>
                            <label><input type="radio" name="QiniuEnable" value="1"/>是</label>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <label><input type="radio" name="QiniuEnable" value="0"/>否</label>
                            <span class='Caution'>还没有七牛账号，请点击<a href="https://portal.qiniu.com/signup?code=3l8fih7gcjfpu" style="color:blue;" target="_blank">免费注册</a>。
                            启用后，系统会将网站静态资源（如：图片、样式表文件等）自动存储到七牛云
                            </span>
                        </td>
                    </tr>

                    <tr>
                        <th>AccessKey</th>
                        <td><input type="text" class="textinput" style="width:320px;" name="QiniuAccessKey" id="QiniuAccessKey" value="{$QiniuAccessKey}"/></td>
                    </tr>
                    <tr>
                        <th>SecretKey</th>
                        <td><input type="text" class="textinput" style="width:320px;" name="QiniuSecretKey" id="QiniuSecretKey" value="{$QiniuSecretKey}"/></td>
                    </tr>
                    <tr>
                        <th>存储空间名</th>
                        <td><input type="text" class="textinput" style="width:320px;" name="QiniuBucketName" id="QiniuBucketName" value="{$QiniuBucketName}"/>
                        <span class='Caution'>设置七牛提供的空间名</span>
                        </td>
                    </tr>
                    <tr>
                        <th>访问域名</th>
                        <td><input type="text" class="textinput" style="width:320px;" name="QiniuUrl" id="QiniuUrl" value="{$QiniuUrl}"/>
                        <span class='Caution'>设置七牛绑定的域名，域名前面要加上http://或https://。如：http://www.xx.com</span>
                        </td>
                    </tr>
                    <tr>
                        <th></th>
                        <td>
                            <a style="float:left;"  onclick="getQiniuUrl()" id="btnPick">获取访问域名</a>
                            &nbsp;&nbsp;<span id="tip"></span>
                        </td>
                    </tr>
                </table>
            </div>
            
            <div class="box-header" id="c1">
                <h4>镜像存储<span style="color:blue; margin-left:8px;">设置好【要镜像的资源扩展名】后，网站的这些静态资源，将自动存储到七牛云；如果扩展名留空则不镜像任何资源！</span></h4>
            </div>
            <div class="box-content">
                <table class="boxtable">
                    <tr>
                        <th>镜像源</th>
                        <td><input type="text" class="textinput" style="width:320px;" name="QiniuMirrorUrl" value="{$QiniuMirrorUrl}"/>
                        <span class='Caution'>镜像源一般是当前网站地址，系统检测到你的域名是：<b style="color:#F30">{:get_web_url()}</b></span>
                        </td>
                    </tr>
                    <tr style="display:none;">
                        <th>图片渐进显示</th>
                        <td>
                            <label><input type="radio" name="QiniuInterlaceEnable" value="1"/>开启</label>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <label><input type="radio" name="QiniuInterlaceEnable" value="0"/>关闭</label>
                            <span class='Caution'>用于jpg格式的图片，当网速慢时，图片显示由模糊到清晰</span>
                        </td>
                    </tr>
                    <tr>
                        <th>要镜像的资源扩展名</th>
                        <td><input type="text" class="textinput" style="width:450px;" name="QiniuFileType" value="{$QiniuFileType}"/></td>
                    </tr>
                    <tr>
                        <th></th>
                        <td><span class='Caution' style="margin:0;">
                        设置要缓存静态文件的扩展名，留空表示不镜像任何静态资源；请使用|分隔开，不支持缓存html，|前后都不要留空格，如：jpg|jpeg|bmp|png|gif|css|js</span></td>
                    </tr>
              </table>
          </div>
          <div class="box-footer">
               <div class="box-footer-inner"><input id="btnSubmit" type="submit" value="保存设置" /></div>
          </div>
        </form>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
function getQiniuUrl(){
	var ak = $("#QiniuAccessKey").val();
	if(ak.length==0){
		ErrorBox("AccessKey不能为空！");
		return;
	}
	var sk = $("#QiniuSecretKey").val();
	if(sk.length==0){
		ErrorBox("SecretKey不能为空！");
		return;
	}
	var bucket = $("#QiniuBucketName").val();
	if(bucket.length==0){
		ErrorBox("存储空间名不能为空！");
		return;
	}

	msg = "<img src='{$WebPublic}Images/loading/9.gif' border='0' align='absmiddle'/>";
	msg += "自动获取储存空间域名，请稍后...";
	$("#tip").html(msg);
	var timenow = new Date().getTime();
	var url = "{$Url}getBucketDomain";
	var p = {
		ak:$("#QiniuAccessKey").val(), 
		sk:$("#QiniuSecretKey").val(), 
		bucket:$("#QiniuBucketName").val(), 
		t:timenow
	};
	$.post(url, p, function(data){
		if(data.status == 1){
			$("#QiniuUrl").val(data.data);
			$("#tip").html( "<span style='color:blue'>"+data.info+"</span>" );
		}else{
			$("#tip").html("<span style='color:red'>"+data.info+"</span>" );
		}
	}, "json");
}
$(document).ready(function(){
	$('#frmConfig').ajaxForm({
		success: complete,
		dataType: 'json'
	});
	
	function complete(data){
		CloseLoadBox();
		if (data.status==1){
			SucceedBox(data.info);
		}else if(data.status==0){
			ErrorBox(data.info);
		}else if(data.status==2){
			ErrorBox(data.info); //上传失败
		}else if(data.status==3){
			$('#'+data.data.ImageField).val(data.data.Path);
			SucceedBox(data.info); //上传成功
		}
	};

	 //保存提交
	 $('#btnSubmit').click(function(){
		$('#frmConfig').attr('action','{$Action}');
	 });
	 
	 $('#frmConfig').submit(function(){
		LoadBox();
		return false;
	 });
	 
	 function pageInit(){
		$("input[name='QiniuEnable'][value={$QiniuEnable}]").attr("checked",'checked');
		$("input[name='QiniuInterlaceEnable'][value={$QiniuInterlaceEnable}]").attr("checked",'checked');
	}
	pageInit();
});
</script>